package lsg;

/**
 * ServiceCompletion is a special SimEvent.
 * Changes the SimState according to the server state if a
 * ServiceCompletion event occurs
 * @author Alexander Klein
 * @version 1.0.0 
 * @since 2005-10-22
 */
public class ServiceCompletion extends SimEvent
{
	/**
	 * Constructor that uses the given argument
	 *@param time Representing the simulation time at which the event occurs
	 */
	public ServiceCompletion (long time)
	{
		value = time;
	}
	/**
	 * Function describes the system behavior depending on the queueSize
	 * if a ServiceCompletion occurs.
	 */
	public void process ()
	{
		/**
		 * If queueSize greater than zero decrease queuesize by one and trigger the next 
		 * ServiceCompletion event.
		 */
		if (s.queueSize > 0) 
		{
			s.ec.insert (new ServiceCompletion (s.now + s.serviceCompletionTime));
			s.queueSize--;
		}
		/**
		 * If queueSize is equal to zero set the server to the idle state.
		 */
		else
		{
			s.serverBusy = false;
		}
	}
}